import axios from 'axios'
const modelUrl = '/produce'

// 模块：原材料采购，辅料采购，其他
export interface PurchaseReq {
  purchaseOrderCode?: string
  supplierId: string
  deliveryDate: string
  isInclTax: number
  formType: number
  purchaseOrderId?: string
  inboundStatus: number
  detailList: {
    purchaseOrderDetailId?: string
    purchaseOrderId?: string
    productId?: string
    productName?: string
    materialCode?: string
    materialDesc?: string
    spec?: string
    specModel?: string
    fluteType?: string
    crimpLine?: string
    unit?: string
    qty?: number
    unitPrice?: number
    amt?: number
    productCategory?: string
    materialName?: string
    calcPriceMethod?: number
  }[]
  remark: string
}
export interface PurchaseRes {
  currentPage?: number
  pageSize?: number
  totalPage?: number
  totalCount?: number
  list: PurchaseResItem[]
}
export interface PurchaseResItem {
  purchaseOrderId: string
  purchaseOrderCode: string
  supplierId: string
  deliveryDate: string
  supplierName: string
  supplierAddress: string
  contactName: string
  contactPhone: string
  purchaseAmt: number
  isInclTax: number
  formType: number
  inboundStatus: number
  detailList: {
    productId?: string
    purchaseOrderDetailId: string
    purchaseOrderId: string
    purchaseOrderCode: string
    productName: string
    materialCode: string
    materialDesc: string
    spec: string
    specModel: string
    fluteType: string
    crimpLine: string
    unit: string
    qty: number
    unitPrice: number
    amt: number
  }[]
  remark: string
  createdBy: string
  createdDt: string
  updatedBy: string
  updatedDt: string
  index?: number // 导出的序号
}

export interface PurchaseItemHandle {
  purchaseOrderId: string
  purchaseOrderCode: string
  supplierId: string
  deliveryDate: string
  supplierName: string
  supplierAddress: string
  contactName: string
  contactPhone: string
  purchaseAmt: number
  isInclTax: number
  formType: number
  purchaseOrderDetailId: string
  materialName: string
  materialCode: string
  materialDesc: string
  spec: string
  fluteType: string
  crimpLine: string
  unit: string
  qty: number
  unitPrice: number
  amt: number
  remark: string
  createdBy: string
  createdDt: string
  updatedBy: string
  updatedDt: string
  index?: number // 导出的序号
  productName: string
  productCategory: string
  specModel: string
  inboundStatus: number
}

export interface PurchaseListSearch {
  supplierName?: string
  createdStartDate?: string
  createdEndDate?: string
  purchaseOrderCode?: string
  deliveryDate?: string
  formType?: number
  purchaseOrderId?: number
  supplierId?: number
  purchaseAmt?: number
  isInclTax?: number
  tenantId?: number
  productName?: string
  deliveryStartDate?: string
  deliveryEndDate?: string
  specModel?: string
}

export interface PurchaseInWarehouseReq {
  materialName: string
  supplierId?: string
  materialCategory?: string
  materialType?: number
  spec: string
  materialCode?: string
  materialDesc?: string
  fluteType?: string
  boxSpec?: string
  crimpLine?: string
  unit?: string
  stockQty?: number
  unitPrice?: number
  purchaseOrderId?: string
  deliveryDate: string
}

// 采购入库
export function purchaseInWarehouse(data: PurchaseInWarehouseReq) {
  return axios.post<PurchaseRes>(modelUrl + '/purchaseMaterialStockAdd', data)
}

export function editPurchase(data: PurchaseReq) {
  return axios.post<PurchaseRes>(modelUrl + '/purchaseOrderAdit', data)
}

export function delPurchase(data: { purchaseOrderId: string }) {
  return axios.post<object>(modelUrl + '/purchaseOrderDel', data)
}

export function getPurchaseDetail(data: { purchaseOrderId: string }) {
  return axios.post<PurchaseResItem>(modelUrl + '/purchaseOrderDetail', data)
}

export function getPurchaseAllList(data?: PurchaseListSearch) {
  return axios.post<PurchaseRes>(modelUrl + '/purchaseOrderList', data)
}

export function getPurchasePageList(data?: PurchaseListSearch) {
  return axios.post<PurchaseRes>(modelUrl + '/purchaseOrderPage', data)
}

export function batchDelPurchase(data?: { idList: string[] }) {
  return axios.post<PurchaseRes>(modelUrl + '/purchaseOrderDelBatch', data)
}
